<?php
/**
 * Commodity.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/5/9
 * Time: 16:10
 */
namespace app\admin\controller;

class Commodity extends Base
{
    public function save()
    {
        if($this->request->isPost())
        {
            $result = (new \app\api\open\commodity\Save($this->request->post()))->index();
            return json(['code'=>200,'data'=>$result]);
        }else if($this->request->isGet())
        {
            $id = $this->request->get('id');
            $info = null;
            if(!empty($id))
            {
                $res1 = \app\api\open\commodity\Get::getInstance()->index(['id'=>$id]);
                if(empty($res1['id']))
                {
                    exit("查询结果为空");
                }
                $info = $res1;
            }
            // 品牌
            $brandList = \app\api\open\commodity\Brand::getInstance()->getAll();
            // 分类
            $categoryList = \app\api\open\commodity\Category::getInstance()->getAll();
            $this->assign('commParam',[
                'brand' => &$brandList,
                'category' => &$categoryList,
                'info' => &$info
            ]);
            return $this->fetch();
        }
        exit("error");
    }
}